use Operation;

package ValidateDirection;

@ISA = qw/Operation/;

sub init{
    my $self = shift;

    $self->dependencies(qw/LogManager/);
}


## Tries to extract a direction in wich to perform the action  
## with the key DIRECTION
## The value must be defined and correspond to a valid direction
# (up, down, etc)
sub perform{
    my $self = shift;

    my $lm = $self->{LogManager};
    my $dir = $self->params->{DIRECTION};
    
    if(!defined($dir)){
	$lm->log((ref $self).": ERROR - No direction specified");
	return 0;
    }
    $dir = uc($dir);
    if($dir ne "UP" &&
       $dir ne "DOWN" &&
       $dir ne "LEFT" &&
       $dir ne "RIGHT"){

	$lm->log((ref $self).": ERROR - Direction \"".$dir."\" invalid");
	return ActionResult->new("FAILURE", "ERROR");
    }
   # $lm->log((ref $self).": OK - Direction found");
    return ActionResult->new("SUCCESS", "OK");
}

1;
